package com.ooolong.expression.operator;

import com.ooolong.expression.ExpressionException;
import com.ooolong.expression.OObject;

public class Multiply extends Operator {
	public Multiply() {
		super("*", 6, true);
		this.type = OObject.MULTIPLY;
	}

	@Override
	public OObject execute(OObject[] args) throws ExpressionException {
		checkArguments(args);

		OObject leftOprand = args[0];
		OObject rightOprand = args[1];
		if (leftOprand.isFloat() || rightOprand.isFloat()) {
			Double res = leftOprand.toDouble() * rightOprand.toDouble();
			return OObject.newInstance(res);
		}
		Long res = leftOprand.toLong() * rightOprand.toLong();
		return OObject.newInstance(res);
	}
}
